<!DOCTYPE html>
<html>
<head>
  <title>武神推演</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/foundation/5.5.3/css/foundation.min.css">
  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/foundation/5.5.3/js/foundation.min.js"></script>
  <script src="https://cdn.staticfile.org/foundation/5.5.3/js/vendor/modernizr.js"></script>
</head>
<body style="padding:20px;">
<ul class="tabs" data-tab="">
  <li class="tab-title active"><a href="#menu0" aria-selected="true" tabindex="0">推演</a></li>
  <li class="tab-title"><a href="#menu1" aria-selected="false" tabindex="1">查看</a></li>
</ul>
<div class="tabs-content">
  <div class="content active" id="menu0" aria-hidden="true" tabindex="0">
    <form id="tuiyan_form">
  		<label for="account">用户名:&nbsp;&nbsp;</label> <input name="account" id="account"/><br/>
        <label for="password">密&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</label> <input name="password" id="password" type="password"/><br/>
        <label for="zone">区&nbsp;&nbsp;服:&nbsp;&nbsp;&nbsp;</label> <input name="zone" id="zone"/><br/>
        <label for="player">角色名:&nbsp;&nbsp;</label> <input name="player" id="player"/><br/>
        <label for="book">自创秘籍:</label> <input name="book" id="book"/><br/>
        <label for="position">推演位置:</label>
        <select name="position" id="position">
            <option value="force" selected>内功</option>
            <option value="unarmed">拳脚</option>
            <option value="throwing">暗器</option>
            <option value="sword">剑法</option>
            <option value="blade">刀法</option>
            <option value="whip">鞭法</option>
            <option value="club">棍法</option>
            <option value="staff">杖法</option>
            <option value="dodge">轻功</option>
            <option value="parry">招架</option>
        </select><br/>
        <label for="">词条:&nbsp;&nbsp;&nbsp;&nbsp;</label><span id="attributes_span"></span><br/>
        <label for="">连续跳不中断:</label>
		<div class="switch round small">
			<input id="continuation" type="checkbox" name="continuation" value="True">
			<label for="continuation"></label>
	  	</div>
        <label for="total">总次数(即:跳多少个10w潜能):&nbsp;&nbsp;</label> <input name="total" id="total"/><br/>
        <label for="step">步数(每10w潜能算一步):&nbsp;&nbsp;&nbsp;&nbsp;</label> <input name="step" id="step"/><br/>
        <label for="feiyiId">飞翼剑ID:&nbsp;&nbsp;</label> <input name="feiyiId" id="feiyiId"/><br/>
        <label for="">是否使用冰心丹:</label>
		<div class="switch round small">
			<input id="haveBingxin" type="checkbox" name="haveBingxin" value="True">
			<label for="haveBingxin"></label>
	  	</div>
	    <button type="button" class="button round" onclick="submitTuiyan()">提交</button>
</form>
  </div>
  <div class="content" id="menu1" aria-hidden="true" tabindex="1">
    <div class="small-5 columns">
    <label>角色名: 
      <input type="text" placeholder="Name" id="player_look">
    </label><button type="button" class="button round small" onclick="look()">查看</button>
	<div id="status_content">
        <label for="playerName">角色名称：<span id="playerName"></span></label>
        <label for="fy">飞翼状态：<span id="fy"></span></label>
        <label for="bx">冰心状态：<span id="bx"></span></label>
        <label for="stopTimes">中断次数：<span id="stopTimes"></span></label>
        <label for="leaveTimes">剩余次数：<span id="leaveTimes"></span></label>
        <label for="pot">当前潜能：<span id="pot"></span></label>
        <label for="loginPot">本次推演登录时总潜能：<span id="loginPot"></span></label>
        <label for="usePot">消耗潜能：<span id="usePot"></span></label>
        <label for="addAttributes">已添加的词条：<span id="addAttributes"></span></label>
        <label for="banAttributes">已放弃的词条：<span id="banAttributes"></span></label>
        <label for="overFlag">是否已经推演结束：<span id="overFlag"></span></label>

	</div>
</div>
  </div>
</div>

<script>
	String.prototype.endWith=function(str){
		var reg=new RegExp(str+"$");
		return reg.test(this);
		}
	    var baseUrl="http://1.15.134.70/server"
		$(document).ready(function() {
   			$(document).foundation();
			initAttrs();
		})
	    function initAttrs(){
			$.get(baseUrl+"/attributes",function(data){
			    var htmlText=""
				for (key in data){
				    htmlText=htmlText+'<label for="attributes_'+key+'"><input name="attributes" id="attributes_'+key+'" type="checkbox" value="'+key+'"/>&nbsp;&nbsp;'+key+'</label>  '
				}
				$("#attributes_span").html(htmlText)
			})
		}
		function submitTuiyan(){
			var fieldArray = $('#tuiyan_form').serializeArray();
			json=paserArrayToJson(fieldArray)
			
			if (json['account'] == ""){
				alert("账号不能为空")
				return
			}
			if (json['password'] == ""){
				alert("密码不能为空")
				return
			}
			if (json['zone'] == ""){
				alert("区服不能为空")
				return
			}
			if (json['player'] == ""){
				alert("角色名不能为空")
				return
			}
			if (json['book'] == ""){
				alert("秘籍不能为空")
				return
			}
			if (json['book'].endsWith("秘籍")){
				alert("不要秘籍两个字")
				return
			}
			if (json['position'] == ""){
				alert("推演位置不能为空")
				return
			}
			if (json.hasOwnProperty('attributes')&&json['attributes']!=""&&json['attributes'].split(",").length>5){
				alert("属性不能超过五个")
				return
			}
			if (json['continuation']==undefined||json['continuation'] == ""){
				json['continuation']="False"
			}
			if (json['total'] == ""){
				alert("总次数不能为空且必须为数字，乱填出问题责任自负")
				return
			}
			if (json['step'] == ""&&json['continuation']=="False"){
				alert("连续跳不中断为否时，步数不能为空且必须为数字，乱填出问题责任自负")
				return
			}
			
			if (json['haveBingxin']==undefined||json['haveBingxin'] == ""){
				json['haveBingxin']="False"
			}
			console.log(json)
			var c;
			if (json['continuation']=="True"){
			    c="将不中断的连续跳"+json['total']+"次"
			}else{
			    c="将每"+json['step']+"下中断一次的跳"+json['total']+"次"
			}
			var a="";
			if (json.hasOwnProperty('attributes')&&json['attributes']!=""){
			    a=json['attributes']
			}
			var r=confirm("账号["+json['account']+"]下的["+json['zone']+"]区的角色["+json['player']+"] 要推演 ["+json['position']+"] 的["+a+"] 属性,"+c+", 是否确定")
			if (r==true){
			    var post=JSON.stringify(json);
				$.post(baseUrl, post, function(data){
					alert("开始推演")
				})
			}
		}
		function paserArrayToJson(array) {
            var result = {};
            for (var i = 0; i < array.length; i++) {
                var field = array[i];
                if (field.name in result) {
                    result[field.name] += ',' + field.value;
                } else {
                    result[field.name] = field.value;
                }
            }
            return result;
        }
                var id=0
		function look1(){
		    $.get(baseUrl+"/log?player="+$("#player_look").val(),function(data){
			    if(data["noPlayer"] == 1){
				    self.clearInterval(id)
					return
			    }
				$("#playerName").text($("#player_look").val())
				if (data["fy"] ){
					$("#fy").text("激活")
				}else{
				    $("#fy").text("未激活")
				}

				if (data["bx"]){
					$("#bx").text("激活")
				}else{
				    $("#bx").text("未激活")
				}

				$("#stopTimes").text(data["stopTimes"])
				$("#leaveTimes").text(data["leaveTimes"])
				$("#pot").text(data["pot"])
				$("#loginPot").text(data["loginPot"])
				$("#usePot").text(data["usePot"])
				if (data["addAttributes"].length>0){
					 var as=""
				    for (i=0;i<data["addAttributes"].length;i++){
					    as=as+data["addAttributes"][i]+","
					}
					$("#addAttributes").text(as)
				}else{
				    $("#addAttributes").text("暂无")
				}
				if (data["banAttributes"].length>0){
				    var as=""
				    for (i=0;i<data["banAttributes"].length;i++){
					    as=as+data["banAttributes"][i]+","
					}
					$("#banAttributes").text(as)
				}else{
				    $("#banAttributes").text("暂无")
				}
				if (data["overFlag"]){
					$("#overFlag").text("已结束")
				}else{
					$("#overFlag").text("未结束")
				}
			},"json")
		}
		function look() {
		    look1()
		    id=self.setInterval("look1()",10000)
        }
		
    </script>
</body>
</html>
